import * as PIXI from 'pixi.js';
export default class ReelBox {
    // 卷轴盒子的容器
    public readonly container: PIXI.Container;
    // 卷轴角精灵
    public readonly hornContainer: PIXI.Container


    constructor(loader: PIXI.Loader, app: PIXI.Application) {
        // 创建一个卷轴盒子容器对象
        this.container = new PIXI.Container();
        // 创建一个卷轴页面容器对象
        this.hornContainer = new PIXI.Container();
        // 创建一个单列卷轴容器对象
        const reelContainer = new PIXI.Container();
        // 通过加载器加载'卷轴盒子背景'的纹理
        const reelContainerBgTexture = <PIXI.Texture>loader.resources!['reelContainerBg.png']!.texture;
        // 通过加载器加载'卷轴角'的纹理
        const hornTexture = <PIXI.Texture>loader.resources!['horn.png']!.texture;
        // 通过'卷轴盒子背景'的纹理创建图像精灵
        const reelContainerBgSprite = new PIXI.Sprite(reelContainerBgTexture);
        // 通过'卷轴角'的纹理创建图像精灵
        const hornSprite = new PIXI.Sprite(hornTexture);

        // 设置图形精灵宽高
        reelContainerBgSprite.width = app.screen.width / 1.3
        reelContainerBgSprite.height = hornSprite.height = app.screen.height / 1.3
        this.hornContainer.width = hornSprite.width = reelContainerBgSprite.width
        this.hornContainer.height = hornSprite.height = reelContainerBgSprite.height - reelContainerBgSprite.height / 13
        // 设置图像精灵位置
        reelContainerBgSprite.x = (app.screen.width - reelContainerBgSprite.width) / 2
        reelContainerBgSprite.y = (app.screen.height - reelContainerBgSprite.height - app.screen.height / 4.2) / 2
        this.hornContainer.x = reelContainerBgSprite.x
        this.hornContainer.y = reelContainerBgSprite.y + reelContainerBgSprite.height / 13

        // 创建'单列卷轴背景'的纹理
        for (let i = 0; i < 5; i++) {
            // 通过加载器加载'单列卷轴背景'的纹理
            const reelTexture = <PIXI.Texture>loader.resources!['reelBg.png']!.texture
            // 通过'单列卷轴背景'的纹理创建图像精灵
            const reelSprite = new PIXI.Sprite(reelTexture);
            // 设置'单列卷轴背景'图像精灵的宽高
            reelSprite.width = reelContainerBgSprite.width / 5 - 5
            reelSprite.height = hornSprite.height / 1.03
            // 设置'单列卷轴背景'图像精灵的横坐标位置
            reelSprite.x = this.hornContainer.x + i * (hornSprite.width / 5) + 3
            reelSprite.y = this.hornContainer.y + (hornSprite.height - reelSprite.height) / 2
            // 将图像精灵添加到容器中
            reelContainer.addChild(reelSprite)
        }
        // 将'卷轴角'精灵添加到容器中
        this.hornContainer.addChild(hornSprite)


        // 将'卷轴盒子背景'图像精灵添加到容器中
        this.container.addChild(reelContainerBgSprite, reelContainer, this.hornContainer)
    }
}